﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DualityEngine.Business.Camera
{
    public class RotatingCamera : Camera
    {
        //Tutorial
        // Set the avatar position and rotation variables.
        private float avatarYaw;
        private Vector3 cameraReference = new Vector3(0, 0, 1);

        // Set rates in world units per 1/60th second (the default fixed-step interval).
        private float rotationSpeed = 1f / 1500f;

        // Set field of view of the camera in radians (pi/4 is 45 degrees).
        private static float viewAngle = MathHelper.PiOver4;

        // Set distance from the camera of the near and far clipping planes.
        private static float nearClip = 1.0f;
        private static float farClip = 200000.0f;

        public RotatingCamera()
            : base()
        {
            this.cameraposition = new Vector3(0, 0, -5000);
            this.projectionmatrix = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip);
        }

        public override void Update(GameTime gameTime)
        {
            // Create a vector pointing the direction the camera is facing.
            Vector3 transformedReference = Vector3.Transform(cameraReference, Matrix.CreateRotationY(avatarYaw));

            // Calculate the position the camera is looking at.
            this.lookat = this.cameraposition + transformedReference;

            // Set up the view matrix and projection matrix.
            this.viewmatrix = Matrix.CreateLookAt(this.cameraposition, this.lookat, new Vector3(0.0f, 1.0f, 0.0f));
            this.projectionmatrix = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip);

            avatarYaw += rotationSpeed;
        }
    }
}
